package com.whut.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hankcs.hanlp.tokenizer.NLPTokenizer;
import com.whut.applicationRunner.ApplicationRunner;
import com.whut.controller.CheckInfoController;
import com.whut.mapper.*;
import com.whut.model.*;
import com.whut.service.AndroidService;
import com.whut.service.CheckInfoService;
import com.whut.utils.FormatDate;
import com.whut.utils.MD5Encoder;
import com.whut.utils.NewMeasureTypeCalculationUtil;
import com.whut.v_model.GroupMemberDetail;
import com.whut.v_model.Municipalprojectinfo;
import com.whut.v_model.ProblemCollectDetail;
import com.whut.v_model.ThirldListAll;
import com.whut.v_vo.GroupPointVO;
import com.whut.v_vo.MeasureDataVO;
import com.whut.v_vo.PointVO;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service("androidService")
public class AndroidServiceImpl implements AndroidService {


    @Resource
    private UserinfoMapper userinfoMapper;
    @Resource
    private GroupMemberDetailMapper groupMemberDetailMapper;
    @Resource
    private ContractchecktaskMapper contractchecktaskMapper;
    @Resource
    private ContracttaskprojectMapper contracttaskprojectMapper;
    @Resource
    private ContracttaskacceptMapper contracttaskacceptMapper;
    @Resource
    private ContractinfoMapper contractinfoMapper;
    @Resource
    private CheckgroupMapper checkgroupMapper;
    @Resource
    private NewProblemDescriptionMapper newproblemdescriptionMapper;
    @Resource
    private ProblemDescriptionMapper problemdescriptionMapper;
    @Resource
    private ResultsinglechildMapper resultsinglechildMapper;
    @Resource
    private ProblemcollectMapper problemcollectMapper;
    @Resource
    private UncheckeditemsMapper uncheckeditemsMapper;
    @Resource
    private SummaryMapper summaryMapper;
    @Resource
    private GroupmemberMapper groupmemberMapper;
    @Resource
    private EquipinfoMapper equipinfoMapper;
    @Resource
    private ProblemCollectDetailMapper problemCollectDetailMapper;
    @Resource
    private AppversionMapper appversionMapper;
    @Resource
    private NoproblemitemMapper noproblemitemMapper;
    @Resource
    private MachineinfoMapper machineinfoMapper;
    @Resource
    private SampleinfoMapper sampleinfoMapper;
    @Resource
    private NewPrefixSystemMapper newprefixsystemMapper;

    @Resource
    private PrefixParSystemMapper prefixParSystemMapper;

    /*and now lets begin*/

    /*新实测实量*/
    @Resource
    private NewmeasuresystemMapper newmeasuresystemMapper;

    @Resource
    private NewmeasureresulttypeMapper newmeasureresulttypeMapper;

    @Resource
    private NewmeasureresulttmpMapper newmeasureresulttmpMapper;

    @Resource
    private NewmeasureresultMapper newmeasureresultMapper;

    //    印证模块
    @Resource
    private EquipverificationsystemMapper equipverificationsystemMapper;

    @Resource
    private EquipVerifyResultMapper equipVerifyResultMapper;

    @Resource
    private NewProblemCollectDetailMapper newProblemCollectDetailMapper;

    @Resource
    private CheckInfoServiceImpl checkInfoServiceImpl;

    @Override
    public Object checkPassword(String userPhone, String password) {
        String realPwd = MD5Encoder.getMD5(password);
        Userinfo userinfo = userinfoMapper.selectByUserPhone(userPhone);
        JSONObject jsonObject = new JSONObject();
        if (userinfo != null && userinfo.getPassword().equals(realPwd)) {
            jsonObject.put("isRight", true);
            JSONObject userJSON = (JSONObject) JSONObject.toJSON(userinfo);
            //增加cookie
            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = attributes.getRequest();
            HttpSession session = request.getSession();
            session.setAttribute("userinfo", userinfo);
            Cookie cookie = new Cookie("username", JSON.toJSONString(userinfo.getUserName() + userinfo.getUserPhone()));
            cookie.setMaxAge(60 * 60 * 24 * 7);
            cookie.setPath("/");
            HttpServletResponse response = attributes.getResponse();
            response.addCookie(cookie);
            List<Groupmember> list = groupmemberMapper.getIsGroupLeader(userinfo.getUserId());
            if (list.size() == 0) {
                userJSON.put("isGroupLeader", false);
            } else {
                userJSON.put("isGroupLeader", true);
            }
            jsonObject.put("data", userJSON);
        } else {
            jsonObject.put("isRight", false);
        }
        return jsonObject;
    }

    @Override
    public Object modifyUserinfo(Userinfo userinfo) {
        try {
            userinfoMapper.updateByPrimaryKeySelective(userinfo);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public Object modifyPwd(int userId, String newPwd, String oldPwd) {
        System.out.println(1111);
        String newPassword = MD5Encoder.getMD5(newPwd);
        String oldPassword = MD5Encoder.getMD5(oldPwd);
        Userinfo userinfo = userinfoMapper.selectByPrimaryKey(userId);
        if (!userinfo.getPassword().equals(oldPassword)) {
            return "errorPwd";
        }
        try {
            Userinfo u = new Userinfo();
            u.setUserId(userId);
            u.setPassword(newPassword);
            userinfoMapper.updateByPrimaryKeySelective(u);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    public Object getGroupMemberDetail(int userId) {
        List<GroupMemberDetail> list = groupMemberDetailMapper.selectAllByUserId(userId);
        JSONArray jsonArray = new JSONArray();
        JSONArray childArray = new JSONArray();
        String teamName = "";

        for (GroupMemberDetail item : list) {
            if (!item.getGroupName().equals(teamName)) {
                if (teamName.equals("")) {
                    childArray.add(item);
                } else {
                    jsonArray.add(childArray);
                    childArray = new JSONArray();
                    childArray.add(item);
                }
                teamName = item.getGroupName();
            } else {
                childArray.add(item);
            }
        }
        jsonArray.add(childArray);
        return jsonArray;

    }


    @Override
    public Object getSelfGroup(int userId) {
        return groupMemberDetailMapper.selectSelfGroup(userId);
    }

    @Override
    public Object getAllGroupList() {
        return checkgroupMapper.getAllCheckGroup();
    }


    @Override
    public Object getTasksByUserId(int userId) {
        return contractchecktaskMapper.getTasksByUserId(userId);
    }

    @Override
    public Object getAllProjects(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ContractTaskProject> list = contracttaskprojectMapper.getAllProject();
        PageInfo result = new PageInfo(list);
        return result;
    }

    @Override
    public Object getAllTaskAcceptList(int userId) {
        return contracttaskacceptMapper.getContracttaskacceptByGroupId(userId);
    }

    @Override
    public Object getAllContractUf() {
        return contractinfoMapper.getAllContractUnFinished();
    }

    @Override
    public String addTaskAccept(Contracttaskaccept con) {
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        con.setNewCreateTime(formatter.format(date));
        con.setLastEditTime(formatter.format(date));
        con.setUploadTime(FormatDate.getDateStringYMD());
        con.setIsFinished("N");
        try {
            contracttaskacceptMapper.insert(con);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }


    @Override
    public Object getConChTaskListByTaskId(int taskId) {
        return contractchecktaskMapper.getByTaskId(taskId);
    }

    @Override
    public String addConTaskProject(JSONObject jsonObject) {
        String creator = jsonObject.getString("creator");
        String checkName = jsonObject.getString("checkName");
        Contracttaskaccept cta = JSON.parseObject(jsonObject.get("cycle").toString(), Contracttaskaccept.class);
        if (jsonObject.getBoolean("isNewProject")) {
            ContractTaskProject ctp = JSON.parseObject(jsonObject.getString("newProject"), ContractTaskProject.class);
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//            Date date = new Date(System.currentTimeMillis());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            ctp.setNewCreateTime(formatter.format(date));
            ctp.setLastEditTime(formatter.format(date));
            ctp.setContractId(cta.getContractId());
            ctp.setTaskId(cta.getTaskId());
            contracttaskprojectMapper.insert(ctp);
            ContractCheckTask cct = new ContractCheckTask();
            cct.setNewCreateTime(formatter.format(date));
            cct.setLastEditTime(formatter.format(date));
            cct.setCheckName(checkName);
            cct.setIsFinish("N");
            cct.setCheckGroupId(cta.getGroupId().toString());
            cct.setContractId(cta.getContractId());
            cct.setTaskId(cta.getTaskId());
            cct.setProjectId(ctp.getProjectId());
            cct.setCheckContentDescription(ctp.getProjectDescription());
            cct.setProjectName(ctp.getProjectName());
            cct.setCreateTime(FormatDate.getDateStringYMDHms());
            contractchecktaskMapper.insert(cct);
        } else {
            ContractTaskProject ctp = contracttaskprojectMapper.selectByPrimaryKey(jsonObject.getInteger("projectId"));
            ContractCheckTask cct = new ContractCheckTask();
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//            Date date = new Date(System.currentTimeMillis());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            cct.setNewCreateTime(formatter.format(date));
            cct.setLastEditTime(formatter.format(date));
            cct.setCheckName(checkName);
            cct.setContractId(cta.getContractId());
            cct.setTaskId(cta.getTaskId());
            cct.setProjectId(ctp.getProjectId());
            cct.setCheckContentDescription(ctp.getProjectDescription());
            cct.setCreateTime(FormatDate.getDateStringYMDHms());
            cct.setCreator(creator);
            cct.setIsFinish("N");
            cct.setCheckGroupId(cta.getGroupId().toString());
            cct.setProjectName(ctp.getProjectName());
            contractchecktaskMapper.insert(cct);
        }

        return "succ";
    }

    @Override
    public Object getEquipTypeNameList(String projectId) {
        List<Map<String, String>> typeNameList = machineinfoMapper.getTypeNameList(projectId);
        return typeNameList;
    }


    @Override
    public Object getEquipSectionAndDescription(String equipType) {
        List<String> equipSection = equipverificationsystemMapper.getEquipSeciton(equipType);
        List<Map<String, String>> mapList = new ArrayList<>();
        for (int i = 0; i < equipSection.size(); i++) {
            List<String> equipDescription = equipverificationsystemMapper.getEquipDescription(equipType, equipSection.get(i));
            HashMap<String, String> stringListHashMap = new HashMap<>();
            stringListHashMap.put("equipSections", equipSection.get(i));
            stringListHashMap.put("list", equipDescription.stream().collect(Collectors.joining(",")));
            if (equipDescription.size() != 0) {            //不为零的时候添加数据
                mapList.add(stringListHashMap);
            }
        }
        return mapList;
    }

    @Override
    public Object getEquipVerifyResuts(String projectId, String equipType, String equipNum) {
        List<EquipVerifyResult> equipVerifyResults = equipVerifyResultMapper.getEquipVerifyResults(projectId, equipType, equipNum);
        return equipVerifyResults;
    }

    @Override
    public Object addEquipVerifyResult(EquipVerifyResult equipVerifyResult) {
        EquipVerifyResult SelectTmp = equipVerifyResultMapper.getResult(equipVerifyResult.getProjectId(), equipVerifyResult.getEquipType(), equipVerifyResult.getEquipNum(), equipVerifyResult.getEquipSection());
        try {
            if (SelectTmp != null) {
//              //这个就是更改之后的操作
                equipVerifyResult.setmKey(SelectTmp.getmKey());
                equipVerifyResultMapper.updateByPrimaryKeySelective(equipVerifyResult);
            } else {
//                这个就是没有执行的结果
                equipVerifyResultMapper.insertSelective(equipVerifyResult);
            }
            return "success";
        } catch (Exception e) {
            System.out.println(e);
            return "error";
        }
    }

    @Override
    public Object getCTPByContractId(int contractId) {
        return contracttaskprojectMapper.getListByContractId(contractId);
    }

    @Override
    public Object getCTPByContractIdandProjectName(int contractId, String projectName) {

        String name = "%" + projectName + "%";
        return contracttaskprojectMapper.getCTPByContractIdandProjectName(contractId, name);
    }

    @Override
    public Object updateProjectinfo(ContractTaskProject ctpInfo) {
        int res = contracttaskprojectMapper.updateProjectinfo(ctpInfo);
        System.out.println(res);
        String result;
        if (res == 1) result = "succ";
        else result = "error";
        return result;
    }


    /*System 体系*/
    @Override
    public Object getSecByFirstName(String firstName) {
        //新体系取代旧体系
        return prefixParSystemMapper.getSecondByFirstName(firstName);
//        return newprefixsystemMapper.getSecondByFirstName(firstName);

    }

    @Override
    public Object getNewSecByFirstName(String firstName) {
        return newprefixsystemMapper.getNewSecondByFirstName(firstName);
    }

    @Override
    public Object getNextSystemByCurNum(int curNumber) {
        return prefixParSystemMapper.getNextSystemByCurNum(curNumber);
//        return newprefixsystemMapper.getNextSystemByCurNum(curNumber);
    }

    @Override
    public Object getNewNextSystemByCurNum(int curNumber) {
        return newprefixsystemMapper.getNewNextSystemByCurNum(curNumber);
    }

    @Override
    public Object getNewNextMeasureTableChooseByNumber(int curNumber) {
        return newmeasuresystemMapper.getNewNextMeasureTableChooseByNumber(curNumber);
    }

    @Override
    public Object getNewLastMeasureTableChooseByNumber(int curNumber, String projectId, String checkId) {
        Newmeasureresulttype newLastMeasureTableChooseByNumber = newmeasureresulttypeMapper.getNewLastMeasureTableChooseByNumber(curNumber);
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(curNumber + "", projectId, checkId);
        int[] checkNum = new int[]{2, 1, 5, 1, 4, 5, 2, 3, 4, 2, 1, 1};
        int fixedNum = Integer.parseInt(newLastMeasureTableChooseByNumber.getCheckPoints()) / checkNum[Integer.parseInt(newLastMeasureTableChooseByNumber.getClassify()) - 1];
        newLastMeasureTableChooseByNumber.setMaxNum(fixedNum + 5);
        newLastMeasureTableChooseByNumber.setCheckPoints(fixedNum + "");
        if (measurePointValues.size() > fixedNum) {
            newLastMeasureTableChooseByNumber.setCheckPoints(measurePointValues.size() + "");
        }
        return newLastMeasureTableChooseByNumber;
    }

    @Override
    public Object getNewNextLastMeasureTableChooseByNumber(int curNumber) {
        List<Newmeasureresulttype> measureResultInfo = newmeasureresulttypeMapper.getMeasureResultInfo(curNumber);
        return measureResultInfo;
    }

    @Override
    public List<List<GroupPointVO>> calcType1(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);

        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType2(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            pointVOS.add(pointVO1);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);

        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType3(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            PointVO pointVO3 = new PointVO();
            pointVO3.setMeasureValue(params.get("actrualValue3"));
            PointVO pointVO4 = new PointVO();
            pointVO4.setMeasureValue(params.get("actrualValue4"));
            PointVO pointVO5 = new PointVO();
            pointVO5.setMeasureValue(params.get("actrualValue5"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            pointVOS.add(pointVO3);
            pointVOS.add(pointVO4);
            pointVOS.add(pointVO5);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);

        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType4(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            pointVOS.add(pointVO1);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);

        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType5(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            pointVOS = new ArrayList<>();
            pointVO1 = new PointVO();
            pointVO2 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue3"));
            pointVO2.setMeasureValue(params.get("actrualValue4"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue2"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType6(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            PointVO pointVO3 = new PointVO();
            pointVO3.setMeasureValue(params.get("actrualValue3"));
            PointVO pointVO4 = new PointVO();
            pointVO4.setMeasureValue(params.get("actrualValue4"));
            PointVO pointVO5 = new PointVO();
            pointVO5.setMeasureValue(params.get("actrualValue5"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            pointVOS.add(pointVO3);
            pointVOS.add(pointVO4);
            pointVOS.add(pointVO5);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType7(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType8(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            PointVO pointVO3 = new PointVO();
            pointVO3.setMeasureValue(params.get("actrualValue3"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            pointVOS.add(pointVO3);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;

    }

    @Override
    public List<List<GroupPointVO>> calcType9(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            pointVOS.add(pointVO1);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            pointVOS = new ArrayList<>();
            pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue2"));
            pointVOS.add(pointVO1);
            groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue(params.get("designValue2"));
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);

            pointVOS = new ArrayList<>();
            pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue3"));
            pointVOS.add(pointVO1);
            groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue((double) 0);
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);

            pointVOS = new ArrayList<>();
            pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue4"));
            pointVOS.add(pointVO1);
            groupPointVO = new GroupPointVO();
            groupPointVO.setDesignValue((double) 0);
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType10(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            PointVO pointVO2 = new PointVO();
            pointVO2.setMeasureValue(params.get("actrualValue2"));
            pointVOS.add(pointVO1);
            pointVOS.add(pointVO2);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType11(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            pointVOS.add(pointVO1);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setDesignValue(params.get("designValue1"));
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public List<List<GroupPointVO>> calcType12(int preNum,String projectId, String checkId) {
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(preNum + "", projectId, checkId);
        List<List<GroupPointVO>> groupPointVOSList = new ArrayList<>();
        for (int i = 0; i < measurePointValues.size(); i++) {
            Newmeasureresulttmp newmeasureresulttmp = measurePointValues.get(i);
            String pointValue = newmeasureresulttmp.getPointValue();
            JSONObject jsonObject = JSONObject.parseObject(pointValue);
            Map<String, Object> innerMap = jsonObject.getInnerMap();
            Map<String, Double> params = innerMap.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> "".equals(e.getValue()) ? 0 : Double.parseDouble((String) e.getValue())));
            ArrayList<GroupPointVO> groupPointVOS = new ArrayList<>();
            ArrayList<PointVO> pointVOS = new ArrayList<>();
            PointVO pointVO1 = new PointVO();
            pointVO1.setMeasureValue(params.get("actrualValue1"));
            pointVOS.add(pointVO1);
            GroupPointVO groupPointVO = new GroupPointVO();
            groupPointVO.setGroupData(pointVOS);
            groupPointVO.setQFPoint(new ArrayList<Double>());
            groupPointVO.setDQFPoint(new ArrayList<Double>());
            groupPointVOS.add(groupPointVO);
            groupPointVOSList.add(groupPointVOS);
        }
        return groupPointVOSList;
    }

    @Override
    public Object newMeasureCalculate(String data) {
        System.out.println(data);
        Newmeasureresult measureresult = new Newmeasureresult();
        JSONObject jsonObject = JSONObject.parseObject(data);
        int modelType = jsonObject.getIntValue("modelType");
        Integer projectId = jsonObject.getIntValue("projectId");
        Integer checkId = jsonObject.getIntValue("checkId");
        String checker = jsonObject.getString("checker");
        String checkPart = jsonObject.getString("checkPart");
        measureresult.setType(modelType);
        measureresult.setChecker(checker);
        measureresult.setCheckId(checkId);
        measureresult.setProjectId(projectId);
        measureresult.setCheckPart(checkPart);
        Newmeasureresulttype newMeasureResultType = jsonObject.getObject("newMeasureResultType", Newmeasureresulttype.class);
        measureresult.setResultTypeId(newMeasureResultType.getmKey());
        //删除原来的数据，进行覆盖。
        newmeasureresultMapper.deleteByResultTypeId(newMeasureResultType.getmKey() + "",projectId.toString(),checkId.toString());

        List<List<GroupPointVO>> groupPointVOS = null;
        List<MeasureDataVO> measureDataVOS = new ArrayList<>();
        List<Newmeasureresulttmp> measurePointValues = newmeasureresulttmpMapper.getMeasurePointValues(newMeasureResultType.getmKey().toString(),projectId.toString(),checkId.toString());
        System.out.println(measurePointValues.size());
        if (measurePointValues.size() != 0) {      //也就是说存在数据，
            String checkTime = measurePointValues.stream().max(Comparator.comparing(Newmeasureresulttmp::getCheckTime)).get().getCheckTime();
            String checkTmp = measurePointValues.stream().min(Comparator.comparing(Newmeasureresulttmp::getCheckTime)).get().getCheckTime();
            checkTime = checkTmp + "+" + checkTime;
            measureresult.setCheckTime(checkTime);
            switch (modelType) {
                case 0: {
                    groupPointVOS = calcType1(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type1(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 1: {
                    groupPointVOS = calcType2(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type2(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 2: {
                    groupPointVOS = calcType3(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type3(e, newMeasureResultType.getRangeMath(), newMeasureResultType.getBurstValue())));
                    break;
                }
                case 3: {
                    groupPointVOS = calcType4(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type4And5(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 4: {
                    groupPointVOS = calcType5(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type4And5(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 5: {
                    groupPointVOS = calcType6(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type6(e, newMeasureResultType.getRangeMath(), newMeasureResultType.getBurstValue())));
                    break;
                }
                case 6: {
                    groupPointVOS = calcType7(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type7(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 7: {
                    groupPointVOS = calcType8(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type8(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 8: {
                    groupPointVOS = calcType9(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type4And5(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 9: {
                    groupPointVOS = calcType10(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type10(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 10: {
                    groupPointVOS = calcType11(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type4And5(e, newMeasureResultType.getRangeMath())));
                    break;
                }
                case 11: {
                    groupPointVOS = calcType12(newMeasureResultType.getmKey(),projectId.toString(),checkId.toString());
                    groupPointVOS.forEach(e -> measureDataVOS.add(NewMeasureTypeCalculationUtil.type12(e, newMeasureResultType.getRangeMath())));
                    break;
                }
            }
            HashMap<String, String> stringStringHashMap = new HashMap<>();

            stringStringHashMap.put("测量点数", measureDataVOS.size() + "");
            List<String> okPoint = new ArrayList<>();
            List<String> noPoint = new ArrayList<>();
            List<String> burstPoint = new ArrayList<>();
            for (int i = 0; i < measureDataVOS.size(); i++) {
                try {
                    if (measureDataVOS.get(i).getIsBurst().equals("爆板")){
                        noPoint.removeAll(noPoint);
                        okPoint.removeAll(okPoint);
                        for (int j = 0; j < measureDataVOS.size(); j++){
                            noPoint.add(Integer.parseInt(measurePointValues.get(j).getPointIndex()) + 1 + "");
                            if (measureDataVOS.get(j).getIsBurst().equals("爆板")){
                                burstPoint.add(Integer.parseInt(measurePointValues.get(j).getPointIndex()) + 1 + "");
                            }
                        }
//                    okPoint.add("0");
                        stringStringHashMap.put("isBurst","true");
                        stringStringHashMap.put("burstPoint",burstPoint.stream().collect(Collectors.joining(",")) );
                        break;
                    }
                }catch (Exception e){}
                if (measureDataVOS.get(i).getTotalQFPointNum().equals(measureDataVOS.get(i).getTotalPointNum())) {
                    okPoint.add(Integer.parseInt(measurePointValues.get(i).getPointIndex()) + 1 + "");
                    stringStringHashMap.put("isBurst","false");
                } else {
                    noPoint.add(Integer.parseInt(measurePointValues.get(i).getPointIndex()) + 1 + "");
                }
            }
            stringStringHashMap.put("合格点", okPoint.stream().collect(Collectors.joining(",")));
            stringStringHashMap.put("不合格点", noPoint.stream().collect(Collectors.joining(",")));
            float v = okPoint.size() / ((float) okPoint.size() + (float) noPoint.size());
            NumberFormat percentInstance = NumberFormat.getPercentInstance();
            percentInstance.setMinimumFractionDigits(0);
            String format = percentInstance.format(v);
            stringStringHashMap.put("合格率", format);
            stringStringHashMap.put("测量点", JSON.toJSONString(measureDataVOS));
            measureresult.setPoint(JSONObject.toJSONString(stringStringHashMap));
            stringStringHashMap.put("state", "ok");
            //删除原来保存的一些数据点
//            measurePointValues.forEach(e -> newmeasureresulttmpMapper.deleteByPrimaryKey(e.getmKey()));
//            在这个地方判断的时候使用，这个需要撤回数据，
            //添加这个数据，在这个result里面
            newmeasureresultMapper.insertSelective(measureresult);
            return stringStringHashMap;
        } else {
            HashMap<String, String> stringStringHashMap = new HashMap<>();
            stringStringHashMap.put("state", "no");
            return stringStringHashMap;
        }
    }

    /*新增一个监测点的值*/
    @Override
    public Object newMeasureAddPointValue(Newmeasureresulttmp data) {
        try {

            Newmeasureresulttmp resultTmpByIndexAndResultId = newmeasureresulttmpMapper.getResultTmpByIndexAndResultId(data.getPointIndex(), data.getResultTypeId(),data.getProjectId(),data.getCheckId());
            if (resultTmpByIndexAndResultId == null) {
                newmeasureresulttmpMapper.insertSelective(data);
            } else {
                //Newmeasureresulttmp newmeasureresulttmp = new Newmeasureresulttmp();
                resultTmpByIndexAndResultId.setPointValue(data.getPointValue());
                resultTmpByIndexAndResultId.setCheckTime(data.getCheckTime());
                newmeasureresulttmpMapper.updateByPrimaryKey(resultTmpByIndexAndResultId);
            }
            return new String[]{"ok"};
        } catch (Exception e) {
            return new String[]{"error"};
        }
    }


    @Override
    public Object withDrawResult(String resultTypeId, String projectId, String checkId) {
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        try {
            newmeasureresultMapper.deleteByResultTypeId(resultTypeId, projectId, checkId);
            stringStringHashMap.put("state", "ok");
            return stringStringHashMap;

        } catch (Exception e) {
            stringStringHashMap.put("state", "no");
            return stringStringHashMap;
        }

    }

    @Override
    public Object getQfPoints(String resultTypeId, String projectId, String checkId) {
        Newmeasureresult resultByResultTypeId = newmeasureresultMapper.getResultByResultTypeId(resultTypeId, projectId, checkId);
        return resultByResultTypeId.getPoint();
    }

    @Override
    public Object getMeasurePointValues(String resultTypeId, String projectId, String checkId) {
        return newmeasureresulttmpMapper.getMeasurePointValues(resultTypeId, projectId, checkId);
    }

    //    得到所有的结果
    @Override
    public Object getAllResult(String resultTypeId, String projectId, String checkId) {
        List<Newmeasureresulttype> measureResultInfo = newmeasureresulttypeMapper.getMeasureResultInfo(Integer.parseInt(resultTypeId));

        HashMap<String, String> stringStringHashMap = new HashMap<>();
        NumberFormat percentInstance = NumberFormat.getPercentInstance();
        percentInstance.setMinimumFractionDigits(0);
        float allPercent = 0;
        boolean flag = false;
        for (int i = 0; i < measureResultInfo.size(); i++) {
            Newmeasureresult allByResultTypeId = newmeasureresultMapper.getResultByResultTypeId(measureResultInfo.get(i).getmKey() + "",projectId,checkId);
            if (allByResultTypeId == null) {
                continue;
            }
            flag = true;
            String point = allByResultTypeId.getPoint();
            List<MeasureDataVO> measureDataVOS = JSON.parseArray(point, MeasureDataVO.class);
            int okPointnum = 0;
            for (int i1 = 0; i1 < measureDataVOS.size(); i1++) {
                if (measureDataVOS.get(i).getTotalQFPointNum().equals(measureDataVOS.get(i).getTotalPointNum())) {
                    okPointnum++;
                }
            }
            allPercent += okPointnum / (float) measureDataVOS.size();
            String format = percentInstance.format(okPointnum / (float) measureDataVOS.size());
            stringStringHashMap.put(allByResultTypeId.getCheckPart(), format);
        }
        if (flag) {
            stringStringHashMap.put("合计", percentInstance.format(allPercent / 4));
            stringStringHashMap.put("state", "ok");
            return stringStringHashMap;
        } else {
            stringStringHashMap.put("state", "ok");
            return stringStringHashMap;
        }
    }

    @Override
    public Object getHasResult(String resultTypeId, String projectId, String checkId) {
        Newmeasureresult resultByResultTypeId = newmeasureresultMapper.getResultByResultTypeId(resultTypeId, projectId, checkId);
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        if (resultByResultTypeId != null) {
            stringStringHashMap.put("state", "ok");
        } else {
            stringStringHashMap.put("state", "no");
        }
        return stringStringHashMap;
    }

    @Override
    public Object getProblemDesListBySixNum(int sixNum) {
        return problemdescriptionMapper.getPDBySixthNum(sixNum);
    }

    @Override
    public Object getNewProblemDesListBySixNum(int sixNum) {
        return newproblemdescriptionMapper.getNewPDBySixthNum(sixNum);

    }


    @Override
    public Object getSystemNextListFromProColl(int checkId, int curNum, int type) {
        return newprefixsystemMapper.getSystemNextListFromProColl(curNum, checkId, type);
    }

    /*resultSingleChild*/

    @Override
    public String addResultSingleChild(Resultsinglechild resultsinglechild) {
        resultsinglechild.setCheckTime(FormatDate.getDateStringYMDHms());
        resultsinglechild.setIsSubmit("N");
        try {
            resultsinglechildMapper.insert(resultsinglechild);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    /*获取单次任务单人的检查列表*/

    @Override
    public Object getPersonalSingleCheckList(int checkId, int userId) {
        return resultsinglechildMapper.getCurrentDoingList(checkId, Integer.toString(userId));
    }


    /*不进行合并，直接存放到这个Problemcollect表里面来进行存放数据，然后就可以进行之后的操作*/
    @Override
    public Object doPersonalMergeOnly(int checkId, int userId) {
        List<Resultsinglechild> list = resultsinglechildMapper.getAllPersonalByCheckId(checkId, Integer.toString(userId));
        List<Resultsinglechild> resList = new ArrayList<>();
        /*将多选的操作分开，然后构成之新的一条数据,多条放到同一条*/
        for (int i = 0; i < list.size(); i++) {
            Resultsinglechild resultsinglechild = list.get(i);
            String checkPart = resultsinglechild.getCheckPart();
            if (checkPart.indexOf(",") >= 0) {       //那么代表这个里面存放的是多个检查的设备
                String[] split = checkPart.split(",");
                String s = JSON.toJSONString(resultsinglechild);//对象序列化
                for (int j = 0; j < split.length; j++) {
                    Resultsinglechild resultsinglechild1 = JSON.parseObject(s, Resultsinglechild.class);
                    resultsinglechild1.setCheckPart(split[j]);
                    resList.add(resultsinglechild1);
                }
            } else {         //如果只有一个，那么代表只有一个
                resList.add(resultsinglechild);
            }
        }
        /*设置转置位*/
        resultsinglechildMapper.updateIsSubmit(checkId, Integer.toString(userId));
        List<Problemcollect> list_p = new ArrayList<>();
        /*进行存储*/
        for (Resultsinglechild r : resList) {
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(r));
            Problemcollect problemcollect = JSON.toJavaObject(jsonObject, Problemcollect.class);
            problemcollect.setPicName(r.getPicFileName());
            list_p.add(problemcollect);
        }
        /*存储*/
        for (Problemcollect problemcollect : list_p) {
            problemcollectMapper.insert(problemcollect);
        }
        return "succ";
    }

    /*单人合并到problemCollect*/
    @Override
    public String doPersonalMerge(int checkId, int userId) {
        //1 取出所有这个人这次行动的所有检查信息列表
        List<Resultsinglechild> list = resultsinglechildMapper.getAllPersonalByCheckId(checkId, Integer.toString(userId));
        //1.1 置标志位为已提交
        resultsinglechildMapper.updateIsSubmit(checkId, Integer.toString(userId));
        //2 进行转化
        List<Problemcollect> list_p = new ArrayList<>();
        for (Resultsinglechild r : list) {
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(r));
            Problemcollect problemcollect = JSON.toJavaObject(jsonObject, Problemcollect.class);
            problemcollect.setPicName(r.getPicFileName());
            list_p.add(problemcollect);
        }
        //3 进行存储
        for (Problemcollect p : list_p) {
            Problemcollect pro = problemcollectMapper.selectByLastIdAndCheckId(p.getLastId(), checkId);
            if (pro == null) {
//                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//                Date date = new Date(System.currentTimeMillis());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date();

                p.setNewCreateTime(formatter.format(date));
                p.setLastEditTime(formatter.format(date));
                p.setOriginRisk(p.getRiskPoint());
//                p.setCorrespondScale("1");
                problemcollectMapper.insert(p);
            } else {
                pro.setSuggestion(pro.getSuggestion() + p.getSuggestion());
                if (p.getIsRemark().equals("Y")) {
                    pro.setIsRemark("Y");
                    pro.setRemark(pro.getRemark() + p.getRemark());//TODO 此处可能有bug
                }
                pro.setSuggestion(pro.getSuggestion() + ";" + p.getSuggestion());
                if (pro.getPicPath().equals("")) {
                    pro.setPicPath(p.getPicPath());
                }
                pro.setPicName(JSONArray.parseArray(pro.getPicName()).fluentAddAll(JSONArray.parseArray(p.getPicName())).toJSONString());
                pro.setCheckPart(pro.getCheckPart() + ";" + p.getCheckPart());
                pro.setReserve1(pro.getReserve1() == null ? null : pro.getReserve1() + ";" + p.getReserve1());
                pro.setReserve2(pro.getReserve2() == null ? null : pro.getReserve2() + ";" + p.getReserve2());
                pro.setReducePoint(pro.getReducePoint().compareTo(p.getReducePoint()) > 0 ? pro.getReducePoint() : p.getReducePoint());
                pro.setProblemQua(pro.getReducePoint().compareTo(p.getReducePoint()) > 0 ? pro.getProblemQua() : p.getProblemQua());
                pro.setExtraReduce(pro.getReducePoint().compareTo(p.getReducePoint()) > 0 ? pro.getExtraReduce() : p.getExtraReduce());
//                pro.setRiskPoint(MyMap.RiskPointMap().get(pro.getRiskPoint()) > MyMap.RiskPointMap().get(p.getRiskPoint()) ? pro.getRiskPoint() : p.getRiskPoint());
                pro.setRiskPoint(pro.getRiskPoint().compareTo(p.getRiskPoint()) > 0 ? pro.getRiskPoint() : p.getRiskPoint());
                if (p.getCorrespondScale() != null && pro.getCorrespondScale() != null) {
                    pro.setCorrespondScale(pro.getCorrespondScale().compareTo(p.getCorrespondScale()) > 0 ? pro.getCorrespondScale() : p.getCorrespondScale());
                }
                pro.setOriginRisk(pro.getRiskPoint());
//                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//                Date date = new Date(System.currentTimeMillis());
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date();
                pro.setLastEditTime(formatter.format(date));
                problemcollectMapper.updateByPrimaryKeySelective(pro);
            }
        }

        return "succ";
    }

    @Override
    public Object getUncheckedSixthList(int fourthId, int checkId) {
        return newprefixsystemMapper.getSixUncheckedList(fourthId, checkId);
    }

    @Override
    public Object getNewUncheckedSixthList(int fourthId, int checkId) {
        return newprefixsystemMapper.getNewSixUncheckedList(fourthId, checkId);
    }

    /**
     * @return java.lang.Object
     * @author Lei
     * @description 将提交的检查的一条记录，然后将这条数据的第四级在无问题项出现不了
     * 虽然下面使用的是noproblemItem，但是里面是resultSingleChild
     * @date 17:29 2021/6/29
     * @params [checkId, firstId, secondId, thirdId]
     */
    @Override
    public Object getFourExcludeId(int checkId, int firstId, int secondId, int thirdId) {
        List<Integer> res = noproblemitemMapper.selectByPreThreeid(checkId, firstId, secondId, thirdId);
        return res;
    }

    /**
     * @return java.lang.Object
     * @Author Lei
     * @Description 根据mkey值来判断来查询是否是新老体系
     * 将这个数据
     * @Date 16:13 2021/7/10
     * @Param [mkey]
     **/
    @Override
    public Object getIsNewByMkey(int mkey) {
        String isNew = resultsinglechildMapper.selectIsNewByMkey(mkey);
        return isNew != null && "1".equals(isNew.trim());           //简化的操作，那么直接就是返回的这个方法
    }

    /*提交各个排除项*/
    /*-wxd-将排除的设备编号存入reserve1*/
    @Override
    public String updateUnsubmit(JSONObject jsonObject) {
        JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("addedItems"));
        int checkId = jsonObject.getInteger("checkId");
        int fourthId = jsonObject.getInteger("fourthId");
        int firstId = jsonObject.getInteger("firstId");
        boolean isRemark = jsonObject.getBoolean("isRemark");
        String reserve1 = jsonObject.getString("checkParts");

        Summary summary = new Summary();
        summary.setCheckId(checkId);
        summary.setFourthId(fourthId);
        summary.setFirstId(firstId);
        summary.setIsSummary("N");
        String remark = "";
        if (isRemark) {
            remark = jsonObject.getString("remark");
            summary.setIsSummary("Y");
            summary.setSummary(remark);
        }
        List<Uncheckeditems> list = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            Uncheckeditems uncheckeditems = new Uncheckeditems();
            uncheckeditems.setCheckId(checkId);
            uncheckeditems.setFourthId(fourthId);
            uncheckeditems.setSixthId(jsonArray.getInteger(i));
            uncheckeditems.setReserve1(reserve1);
            list.add(uncheckeditems);
        }
        try {
            if (list.size() != 0) {
                uncheckeditemsMapper.insertList(list);
            }
            summaryMapper.insert(summary);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String updateFinishState(int checkId) {
        try {
            String curTime = FormatDate.getDateStringYMD();
            ContractCheckTask contractchecktask = contractchecktaskMapper.selectByPrimaryKey(checkId);
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//            Date date = new Date(System.currentTimeMillis());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            contractchecktask.setLastEditTime(formatter.format(date));
            contractchecktask.setIsFinish("Y");
            contractchecktask.setFinishTime(curTime);

            contractchecktaskMapper.updateByPrimaryKeySelective(contractchecktask);
            int projectId = contractchecktask.getProjectId();
            ContractTaskProject contracttaskproject = new ContractTaskProject();
            contracttaskproject.setProjectId(projectId);
            contracttaskproject.setLatestCheckTime(curTime);
            contracttaskprojectMapper.updateByPrimaryKeySelective(contracttaskproject);
            //     List<MunicipalSafetyInspection> MSIInfo = getMunicipalSafetyInspection(checkId);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String getIsHead(int userId, int groupId) {
        List<Groupmember> list = groupmemberMapper.getIsHeaderNumber(userId, groupId);
        if (list.size() == 0) {
            return "N";
        } else {
            return "Y";
        }
    }

    @Override
    public String getIsYJLUser(int userId) {
        String position = userinfoMapper.getPosition(userId + "");
        boolean test = position.contains("雅居乐");//如果含有这个三个字的，那么就会返回真，然后就可以进行之后的操作。
        if (test) {
            return "Y";
        } else {
            return "N";
        }
    }

    @Override
    public String saveSigs(ContractCheckTask contractchecktask) {
        try {
//            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//            Date date = new Date(System.currentTimeMillis());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            contractchecktask.setLastEditTime(formatter.format(date));
            contractchecktaskMapper.updateByPrimaryKeySelective(contractchecktask);
            ;
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String getIsCheckFinished(int checkId) {
        ContractCheckTask contractchecktask = contractchecktaskMapper.selectByPrimaryKey(checkId);
        return contractchecktask.getIsFinish();
    }

    @Override
    public Object getDeviceListByProjectId(int projectId) {
        return equipinfoMapper.getAllByProjectId(projectId);
    }

    @Override
    public String deleteDeviceInfoByEquipId(int equipId) {
        try {
            equipinfoMapper.deleteByPrimaryKey(equipId);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String updateDeviceInfo(Equipinfo equipinfo) {
        try {
            equipinfoMapper.updateByPrimaryKeySelective(equipinfo);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String addDeviceInfo(Equipinfo equipinfo) {
        try {
            equipinfoMapper.insert(equipinfo);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public Object getUpdate(String currentVersion) {
        /*Userinfo u = userinfoMapper.selectByPrimaryKey(14);
        String latestVersion = u.getReserve1();
        JSONObject jsonObject = new JSONObject();
        if(currentVersion.equals(latestVersion)){
            jsonObject.put("isLatest",true);
        }else {
            jsonObject.put("isLatest",false);
            jsonObject.put("latestURL",urlProperties.getAddress()+"/examples/files/yiruiapp"+latestVersion+".apk");
        }
        return jsonObject;*/
        JSONObject jsonObject = new JSONObject();
        Appversion appversion = appversionMapper.getLatestVersion();
        if (currentVersion.equals(appversion.getVersion())) {
            jsonObject.put("isLatest", true);
            /*JSONArray jsonArray = JSONArray.parseArray(appversion.getVersionLog());
            jsonObject.put("versionLog",jsonArray);*/
        } else {
            jsonObject.put("isLatest", false);
            jsonObject.put("latestURL", appversion.getDownloadLink());
        }
        return jsonObject;
    }

    /**
     * @return java.lang.Object
     * @author Lei
     * @description 但是这个新的应该没有什么问题啊
     * @date 10:33 2021/4/15
     * @params [checkId, fourthId]
     */
    @Override
    public Object getTLExamineList(int checkId, int fourthId) {

//        return problemcollectMapper.getTLExamineList(checkId, fourthId);
        //现在直接通过新表来查，然后得到之后的事情
        return problemcollectMapper.getNewTLExamineList(checkId, fourthId);
    }

    @Override
    public Object getTeamLeaderModifyIniInfo(int mkey) {
        ProblemCollectDetail p = newProblemCollectDetailMapper.getPCDBymkey(mkey);
        JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(p));
        /*List<Prefixsystem> list5 = prefixParSystemMapper.getNextSystemByCurNum(p.getPreNum4());
        List<Prefixsystem> list6 = prefixParSystemMapper.getNextSystemByCurNum(p.getPreNum5());
        List<Problemdescription> list7 = newproblemdescriptionMapper.getPDBySixthNum(p.getSixthId());
        jsonObject.put("list5",list5);
        jsonObject.put("list6",list6);
        jsonObject.put("list7",list7);*/
        ProblemDescription pd = newproblemdescriptionMapper.selectByPrimaryKey(p.getLastId());
        String sugList = pd.getSuggestion();
        JSONArray jsonArray = JSONArray.parseArray(sugList);
        jsonObject.put("suggestionList", jsonArray);
        jsonObject.put("scale", pd.getScale());
        jsonObject.put("scaleNum", pd.getScaleNum());
        jsonObject.put("problemRn", pd.getProblemRn());
        jsonObject.put("riskNumber", pd.getRiskNumber());
        return jsonObject;
    }

    @Override
    public String delProbCollRecord(int mkey) {
        try {
            problemcollectMapper.deleteByPrimaryKey(mkey);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String updateProbCollInfo(Problemcollect problemcollect) {
//        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
//        Date date = new Date(System.currentTimeMillis());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        problemcollect.setLastEditTime(formatter.format(date));
        try {
            problemcollectMapper.updateByPrimaryKeySelective(problemcollect);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public String getLatestVersionQRcode() {
        /*Userinfo u = userinfoMapper.selectByPrimaryKey(14);
        String latestVersion = u.getReserve1();*/
        Appversion appversion = appversionMapper.getLatestVersion();
        /*String latestVersion = appversion.getVersion();
        //获得最新版本app的apk文件资源链接
        String url = urlProperties.getAddress()+"/examples/files/yiruiapp"+latestVersion+".apk";
        return QRCodeUtil.getQRCodeURL(url);*/
        return appversion.getQrCode();
    }

    @Override
    public Object getPersonalCheckList(int userId, int pageNum, int pageSize) {
        String checker = Integer.toString(userId);
        PageHelper.startPage(pageNum, pageSize);
        List<ContractCheckTask> list = contractchecktaskMapper.getByInvolvedByRSC(checker);
        PageInfo result = new PageInfo(list);
        return result;
    }

    @Override
    public Object getPerSIByCheckId(int userId, int checkId) {
        return resultsinglechildMapper.getFinByUserIdCheckId(userId, checkId);
    }

    @Override
    public Object getPerSIByCheckIdNew(int userId, int checkId) {
        return resultsinglechildMapper.getFinByUserIdCheckIdNew(userId, checkId);
    }

    @Override
    public Object getRSCDetail(int mkey) {
        return resultsinglechildMapper.getRSCDetail(mkey);
    }

    @Override
    public Object getRSCDetailNew(int mkey) {
        return resultsinglechildMapper.getRSCDetailNew(mkey);
    }

    @Override
    public String updateAPPVersion(String version) {
        Userinfo userinfo = new Userinfo();
        userinfo.setUserId(14);
        userinfo.setReserve1(version);
        try {
            userinfoMapper.updateByPrimaryKeySelective(userinfo);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    /*@Override
    public Object getSignListByUserId(String userId) {
        PageHelper.startPage(pageNum,pageSize);
        List<ContractCheckTask> list = contractchecktaskMapper.getByInvolvedByRSC(checker);
        PageInfo result = new PageInfo(list);
    }*/

    @Override
    public Object getSignListByUserId(int userId, int curPage, int pageSize) {
        PageHelper.startPage(curPage, pageSize);
        List<ContractCheckTask> list = contractchecktaskMapper.getByGroupHeaderId(userId);
        PageInfo result = new PageInfo(list);
        return result;
    }

    @Override
    public String addNoProblem(Noproblemitem noproblemitem) {
        try {
            noproblemitemMapper.insert(noproblemitem);
            return "succ";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * @author: wxd
     * @Description: SampleType为0时为全检，否者为抽检
     * @date: 2020-07-23 22:11:07
     * @param: projectId；taskId；curNumber
     */
    @Override
    public Object getEquipNumByCurNum(int projectId, int taskId, int curNumber) {
        List<String> list = machineinfoMapper.getEquipNumByCurNum(projectId, curNumber);
        Sampleinfo sample = sampleinfoMapper.getSampleTypeById(projectId, taskId);
        String[] sampleIndex = sample.getSampleIndex().replace(';', ',').split(",");
        if (sample.getSampleType() == 1) {
            return list;
        } else if (sample.getSampleType() == 0) {
            List<String> result = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                for (int j = 0; j < sampleIndex.length; j++) {
                    if (sampleIndex[j].equals(list.get(i))) {
                        result.add(sampleIndex[j]);
                        break;
                    }
                }
            }
            return result;
        }
        return null;
    }

    /**
     * 获取到的抽样的一个设备名称
     *
     * @param projectId
     * @param taskId
     * @param equipType
     * @return
     */
    @Override
    public Object getEquipNumList(String projectId, String taskId, String equipType) {

        List<Map<String, String>> numList = machineinfoMapper.getEquipNameList(projectId, equipType);
        Sampleinfo sampleByProjectId = sampleinfoMapper.getSampleTypeById(Integer.parseInt(projectId), Integer.parseInt(taskId));
        System.out.println(JSON.toJSONString(sampleByProjectId));
        String[] sampleIndex = sampleByProjectId.getSampleIndex().replace(';', ',').split(",");
        if (sampleByProjectId.getSampleType() == 1) {
            return numList;
        } else if (sampleByProjectId.getSampleType() == 0) {
            List<Map<String, String>> res = new ArrayList<>();
            for (int i = 0; i < numList.size(); i++) {
                for (int j = 0; j < sampleIndex.length; j++) {
                    if (sampleIndex[j].equals(numList.get(i).get("parameterName"))) {
                        res.add(numList.get(i));
                        break;
                    }

                }
            }
            return res;
        }
        return null;
    }


    @Override
    public Object getEquipNumByChecker(int projectId, int firstId, int fourthId, int checker) {
        return resultsinglechildMapper.getEquipNumByChecker(projectId, firstId, fourthId, checker);
    }

    @Override
    public Object getSampleEquipByProjectId(int projectId) {
        return sampleinfoMapper.getSampleEquipByProjectId(projectId);
    }

    @Override
    public Object requestThirdListAll(int checkId) {
        /* 增加无问题项？？？ */
//        List<ProblemCollectDetail> problemCollectDetails = problemCollectDetailMapper.requestThirdListAll(checkId);
        List<ProblemCollectDetail> problemCollectDetails = problemCollectDetailMapper.requesNewtThirdListAll(checkId);
        List<ThirldListAll> result = new ArrayList<>();

        // 将同级的fourthId合并到fourthList
        for (int i = 0; i < problemCollectDetails.size(); i++) {

            int id3 = problemCollectDetails.get(i).getThirdId();
            int j;
            int flag = 0;
            for (j = 0; j < result.size(); j++) {
                if (id3 == result.get(j).getThirldId()) {
                    flag = 1;
                    break;
                }
            }

            if (flag == 0) {
                ThirldListAll thirldListAll = new ThirldListAll();
                thirldListAll.setThirldId(id3);
                thirldListAll.setpName3(problemCollectDetails.get(i).getpName3());
                Map map = new HashMap<>();
                map.put("fourthId", problemCollectDetails.get(i).getFourthId());
                map.put("pName4", problemCollectDetails.get(i).getpName4());
                List<Object> fourList = new ArrayList<>();
                fourList.add(map);
                thirldListAll.setFourthList(fourList);
                result.add(thirldListAll);
            } else {
                Map map = new HashMap<>();
                map.put("fourthId", problemCollectDetails.get(i).getFourthId());
                map.put("pName4", problemCollectDetails.get(i).getpName4());
                result.get(j).getFourthList().add(map);
            }

        }
        return result;
    }

    /***
     * @auther lyl
     * //语义匹配
     * @date 10:13 2020/11/1
     * @param text
     * @return java.util.List<java.lang.String>
     */
    @Override
    public List<Word2VecSystem> getMatchingText(String text) {
        List<Map.Entry<Integer, Float>> stringList = ApplicationRunner.docVectorModel.nearest(text, 20); //自动获取语义最接近的20项的数组编号和相似度
        List<Word2VecSystem> resList = new ArrayList<Word2VecSystem>(); //返回的LIST 详细信息、相似度
        stringList.forEach(item -> {
            String resPd = ApplicationRunner.userDictionary[item.getKey()];
//            String str = "相似度:" + item.getValue() + "\n匹配项:" + resPd;
            List<ProblemDescription> lastIdList = newproblemdescriptionMapper.getLastIdByPDText(resPd); //通过字典中找到的文本反向查找LastId
            if (lastIdList.size() > 0) {
                lastIdList.forEach(e -> {
                    Word2VecSystem wvs = new Word2VecSystem();
                    List<Word2VecResult> paraList = newprefixsystemMapper.getParameterByNum(e.getPreNum()); //反向查找所有前置体系
                    if (paraList.size() < 6) return; //如果缺少前置体系，continue
                    boolean isAvailable = true; //为true则加入返回列表里，否则跳出内层循环
                    for (Word2VecResult i : paraList) { //将前置体系映射到返回结果中
                        if (i.getIsDeprecated().equals("Y")) {//如果体系已废弃，直接跳出循环
                            isAvailable = false;
                            break;
                        }
                        switch (i.getNodeDepth()) {
                            case 6:
                                wvs.setSixthName(i.getParameterName());
                                wvs.setSixthId(i.getNumber());
                                break;
                            case 5:
                                wvs.setFifthName(i.getParameterName());
                                wvs.setFifthId(i.getNumber());
                                break;
                            case 4:
                                wvs.setFourthName(i.getParameterName());
                                wvs.setFourthId(i.getNumber());
                                break;
                            case 3:
                                wvs.setThirdName(i.getParameterName());
                                wvs.setThirdId(i.getNumber());
                                break;
                            case 2:
                                wvs.setSecondName(i.getParameterName());
                                wvs.setSecondId(i.getNumber());
                                break;
                            case 1:
                                wvs.setFirstName(i.getParameterName());
                                wvs.setFirstId(i.getNumber());
                                break;
                        }
                    }
                    if (isAvailable == true) {
                        wvs.setLastId(e.getNumber());
                        wvs.setProblemNum(e.getProblemNum());
                        wvs.setDeductPoint(e.getDeductPoint());
                        wvs.setRiskLevel(e.getRiskLevel());
                        wvs.setExtraPoint(e.getExtraPoint());
                        wvs.setNormsProvison(e.getNormsProvison());
                        wvs.setSuggestion(e.getSuggestion());
                        wvs.setSimilarity(item.getValue());
                        wvs.setProblemDescription(resPd);
                        resList.add(wvs);
                    }
                });
            } else {
              /*  intList = problemcollectMapper.getSixthIdByRemark(ApplicationRunner.userDictionary[item.getKey()]);
                intList.forEach(e -> {

                });*/
            }
        });
        return resList;
    }

    @Override
    public String segmentSentence(String text) {
        Object[] obj = NLPTokenizer.segment(text).toArray();
        String str = "";
        for (int j = 0; j < obj.length; j++) {
            String temp = obj[j].toString();
//            int index = temp.indexOf("/");
//            obj[j] = temp.substring(0, index) + " ";
//            str += obj[j];  //去掉词性
            str += temp + " ";
        }
        System.out.println(str);
        return str;
    }

    @Override
    public Object getProjectInfo(int projectId) {
        return contracttaskprojectMapper.selectAllByProjectId(projectId);
    }


    /**
     * @author wangqirui
     * @desc 处理市政提交项目安监巡检隐患接口所需数据
     * @date 2021/8/17
     **/
    @Override
    public Object getMunicipalSafetyInspection(int checkId) throws Exception {
        /*数据主体*/
        List<Problemcollect> problemCollects = problemcollectMapper.getProblemsBycheckId(checkId);
        List<MunicipalSafetyInspection> municipalSafetyInspectionList = new ArrayList<>();
//        for (Problemcollect problemCollect : problemCollects){
        for (int i = 0; i < problemCollects.size(); i++) {
            Problemcollect problemCollect = problemCollects.get(i);
            MunicipalSafetyInspection MSI = new MunicipalSafetyInspection();
            //默认的账户
            MSI.setThird_account("data_inspection_log");
//            以下两项暂时为0
            MSI.setCheckStatus(0);
            MSI.setHiddenNumber(0);
//            重写了setHiddenScope
            MSI.setHiddenScope(problemCollect.getProblemQua());
            if (problemCollect.getCorrespondScale() == null) {
                continue;
            }
            MSI.setHiddenType(Integer.parseInt(problemCollect.getCorrespondScale()));
            List<String> name = resultsinglechildMapper.getCheckerByCheckIdProjectIdLastId(
                    problemCollect.getCheckId(),
                    problemCollect.getProjectId(),
                    problemCollect.getFourthId()
            );
            MSI.setInspectionPlanNo(checkId);
            MSI.setInspectionMan(name.get(0));
            MSI.setInspectionPlanName("日常监督");
            MSI.setInspectionTime(problemCollect.getLastEditTime());
            ContractTaskProject ctp = contracttaskprojectMapper.getProjectInfoByProjectId(problemCollect.getProjectId());
            String projectCode = ctp.getprojectCode();
            MSI.setProjId(projectCode);
            MSI.setTroubleCentent(problemCollect.getRemark(), problemCollect.getSuggestion());
            List<ProblemDescription> pd = newproblemdescriptionMapper.findAllByNumber(problemCollect.getLastId());
            if (pd.get(0).getCode() == null) {
                continue;
            }
            MSI.setTroubleCode(pd.get(0).getCode());
            String str=problemCollect.getPicName().replace("\"","");
            str=str.replace("[","");
            str=str.replace("]","");
            String[] picName=str.split(",");
            String picPath="http://47.102.106.48:8080/upload/img/";
            String troubleImgPath="";
            for (int j = 0 ; j < picName.length-1 ; j++){
                troubleImgPath += picPath+picName[j]+",";
            }
            troubleImgPath +=picPath+picName[picName.length-1];
            MSI.setTroubleImgPath(troubleImgPath);
            List<ContractCheckTask> sign = contractchecktaskMapper.getBaseData(checkId);
            String signPath = "http://47.102.106.48:8080/upload/signature/";
            String buildingUnitSignPath=signPath+ sign.get(0).getSgSign();
            String constructionUnitSignPath=signPath + sign.get(0).getJsSign();
            String supervisorUnitSignPath=signPath + sign.get(0).getJlSign();
            MSI.setBuildingUnitSignPath(buildingUnitSignPath);
            MSI.setConstructionUnitSignPath(constructionUnitSignPath);
            MSI.setSupervisorUnitSignPath(supervisorUnitSignPath);
            List<ContractTaskProject> header = contracttaskprojectMapper.getHeader(checkId);
            MSI.setImageProgress(header.get(0).getProgress());
            String inspectionRecordReportPath = "";
            inspectionRecordReportPath = checkInfoServiceImpl.generateCheckReport(problemCollect.getProjectId(), checkId, 2,true);
            MSI.setInspectionRecordReportPath(inspectionRecordReportPath);
            String inspectionRecordReportName=inspectionRecordReportPath.replace("http://47.102.106.48:8080/doc/","");
            inspectionRecordReportName=inspectionRecordReportName.replace(".doc","");
            MSI.setInspectionRecordReportName(inspectionRecordReportName);
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date();
            MSI.setInspectionRecordReportAddTime(formatter.format(date));
            municipalSafetyInspectionList.add(MSI);
        }
        return municipalSafetyInspectionList;
    }

}
